package com.flyqiu.flow.api.script;

import java.util.List;

public interface FlyQiuFlowVarSerializeManage {
    /**
     * 注册类型转换器
     *
     * @param converter
     */
    default void register(IVarSerialize converter) {
        register(converter, Integer.MAX_VALUE);
    }

    /**
     * 注册类型转换器
     *
     * @param converter 类型转换器
     * @param priority  优先级
     */
    void register(IVarSerialize converter, int priority);

    /**
     * 获取全部类型转换器
     *
     * @return
     */
    List<? extends IVarSerialize> converters();


    default VarSerialize serialize(Object val) {
        return serialize(val, null);
    }

    VarSerialize serialize(Object val, String varType);

    /**
     * 反序列化
     *
     * @param varSerialize
     * @return
     */
    default Object deserialize(VarSerialize varSerialize) {
        return deserialize(varSerialize.getVarType(), varSerialize.getVarData());
    }

    Object deserialize(String type, String val);
}
